package org.example;

import org.checkerframework.checker.units.qual.C;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author zhangjg
 * @desc m
 * @date 2023/04/26 11:14
 **/
@Component
public class Monitory {

    private static final Logger logger = LoggerFactory.getLogger(Monitory.class);
    private static boolean flag = true;

    public Monitory(){
        if(flag) {
            run();
        }
        flag = false;
    }

    public void run(){
        new Thread(){
            @Override
            public void run() {
                while (true){
                    logger.info("ClientNum={}",MyWsHandler.getClientNum());
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();

    }
}
